package com.zhuoshi.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zhuoshi.bean.WdContract;
import com.zhuoshi.bean.WdHtCustomer;
import com.zhuoshi.bean.WdHtRoom;
import com.zhuoshi.service.WdContractService;
import com.zhuoshi.service.WdHtCustomerService;
import com.zhuoshi.service.WdRoomService;

@Controller
@RequestMapping("/contract")
public class WdContractController {

	@Autowired
	private WdContractService contractService;
	@Autowired
	private WdHtCustomerService customerService;
	@Autowired
	private WdRoomService roomService;
	/**
	 * 查询所有合同信息和模糊查询
	 */
	@RequestMapping("/list.do")
	public String selectList(WdContract bean,Model model){
		List<WdContract> list = contractService.selectList(bean);
		System.out.println(list.isEmpty());
		model.addAttribute("clist", list);
		return "contract_list";
	}
	/**
	 * 删除
	 */
	@RequestMapping("/delete.do")
	public String delete(String contractId){
		contractService.deleteByPrimaryKey(contractId);
		return "redirect:list.do";
	}
	/**
	 * 修改前查询
	 */
	@RequestMapping("/toupdate.do")
	public String toupdate(String contractId,Model model){
		WdContract bean = contractService.selectByPrimaryKey(contractId);
		List<WdHtRoom> roomList = roomService.selectAll(null);
		List<WdHtCustomer> customerList = customerService.getlist(null);
		model.addAttribute("bean",bean) ;
		model.addAttribute("roomList", roomList);
		model.addAttribute("customerList", customerList);
		return "contract_update";
	}
	/**
	 * 修改
	 */
	@RequestMapping("/update.do")
	public String update(WdContract record){
		contractService.updateByPrimaryKeySelective(record);
		return "redirect:list.do" ;
	}
	
}
